﻿<%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="NewLocationBasedNotification.aspx.cs" Inherits="Agents.Admin.NewLocationBasedNotification" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />

    <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.4/js/dojo/dijit/themes/claro/claro.css">
    <link href="../Styles/SiteMaster.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.4"></script>
    <style type="text/css" media="screen">

      .segment { cursor:pointer; padding-top:3px; padding-bottom:3px; }

    </style>

    <script type="text/javascript">
        dojo.require("esri.map");
        dojo.require("esri.tasks.locator");
        var map, locator, extentToZoom;

        function init() {
            esri.config.defaults.io.proxyUrl = "/proxy/proxy.ashx";
            map = new esri.Map("map");

            map.addLayer(new
                esri.layers.ArcGISTiledMapServiceLayer(
                "http://www10.emap.co.il/ArcGIS/rest/services/eMap_vector_2010/MapServer"));

            // Create geocoder  
            locator = new esri.tasks.Locator(
                "http://www10.emap.co.il/ArcGIS/rest/services/eMapComposite/GeocodeServer");

            // Draw and zoom to the result when the geocoding is complete                
            dojo.connect(locator, "onAddressToLocationsComplete", showAddress);

            // Create Point Collection
            extentToZoom = new esri.geometry.Multipoint(new esri.SpatialReference({ wkid: 4326 }));
        }

        dojo.addOnLoad(init);

        // Add a point to the wanted address, on map                
        function locateAddress() {

            var address = { City: document.getElementById("txtCity").value, 
                            Street: document.getElementById("txtStreet").value,
                            House: document.getElementById("txtStreetNum").value
                        };
            locator.addressToLocations(address, ["Loc_name"]);
        }

        // Shows the address on the map
        function showAddress(addressResults) {

            var geom = addressResults[0].location;
            point = new esri.geometry.Point(
                { "x": geom.x, "y": geom.y, " spatialReference": { " wkid": 4326} });
            var sym = new esri.symbol.SimpleMarkerSymbol().setColor(
                new dojo.Color([255, 0, 0]));
            var graphic = new esri.Graphic(point, sym);

            map.graphics.add(graphic);

            // Add point to the collection
            extentToZoom.addPoint(point);

            // Don't allow to add anymore locations, 
            // and allow to add notification
            document.getElementById('btnShowOnMap').disabled = true;
            document.getElementById('okBtn').disabled = false;

            // Save the location to hidden fields
            document.getElementById('hiddenLocationX').value = geom.x;
            document.getElementById('hiddenLocationY').value = geom.y;
        }

        // Make sure the notification has content
        function validate() {

            // Validate only if we clicked the "OK" button
            if ((document.getElementById('txtContent').value == '') &&
                (document.getElementById('buttonClicked').value != 'backBtn')) {

                alert('יש להזין את תוכן ההתראה');
                return false;
            }

            return true;
        }
    </script>

  </head>
  <body dir="rtl">
      <form id="form1" runat="server" autocomplete="off" onsubmit="return validate();">
        <asp:HiddenField runat="server" id="hiddenLocationX" />
        <asp:HiddenField runat="server" id="hiddenLocationY" />
        <div>
        <table border="0" width="100%">
        <tr class="header">
            <td colspan="2">
                <asp:Image ID="Image1" runat="server" ImageUrl="~/images/background.jpg" ImageAlign="Middle" />
            </td>
        </tr>
        <tr class="mainContent" Width="100%">
            <td>
            <h1>
                הוספת התראה מבוססת מיקום
            </h1>           
            <hr />       
            <asp:ScriptManager ID="ScriptManager1" runat="server" />  
            <asp:Timer ID="redirectionTimer" runat="server" Interval="2000" Enabled="false" 
                ontick="redirectionTimer_Tick" />              
            <table border="0" cellpadding="0" cellspacing="0" Width="100%">
                <tr>
                    <td class="title">
                        <asp:Label ID="Label1" Text="תוכן ההתראה:" runat="server" />
                    </td>
                    <td class="textbox">
                        <asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" 
                            MaxLength="100" Width="100%" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Label ID="lblMessage" runat="server" Text="" />                        
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                       <asp:Panel ID="panelMap" runat="server" GroupingText="מיקום">
                       בחר מיקום על המפה, ע"י מילוי הכתובת ולחיצה על "הצג על המפה":
                        <table>
                            <tr>
                               <td class="title">
                                    <asp:Label ID="Label2" Text="רחוב:" runat="server" />
                                </td>
                                <td class="textbox">
                                    <asp:TextBox ID="txtStreet" runat="server" />
                                </td>
                            </tr>
                            <tr>
                                <td class="title">
                                    <asp:Label ID="Label3" Text="מס' בית:" runat="server" />
                                </td>
                                <td class="textbox">
                                    <asp:TextBox ID="txtStreetNum" runat="server" />
                                </td>
                            </tr>
                            <tr>
                                <td class="title">
                                    <asp:Label ID="Label4" Text="עיר:" runat="server" />
                                </td>
                                <td class="textbox">
                                    <asp:TextBox ID="txtCity" runat="server" />
                                </td>
                            </tr>
                            <tr>
                                <td />
                                <td>
                                    <input type="button" ID="btnShowOnMap" value="הצג על המפה"
                                        class="button" onclick="locateAddress()" />
                                </td>
                            </tr>
                          </table>
                          <div id="map" style="width:500px; height:300px;" class="alignCenter"></div>
                       </asp:Panel>
                    </td>
                </tr>
            </table>              
        
            <br />           
            <hr />
            <div class="alignCenter">               
                <input type="hidden" id="buttonClicked" />          
                <asp:Button ID="okBtn" Text="אישור" runat="server" 
                    onclick="okBtn_Click" CssClass="button" Enabled="false" />                
                <asp:Button ID="backBtn" Text="חזור" runat="server" onclick="backBtn_Click" 
                    CssClass="button" CausesValidation="false" 
                    OnClientClick="document.getElementById('buttonClicked').value = 'backBtn';" />
            </div>
            </td>
        </tr>
        </table>
        </form>
    </body>
</html>
